// 图中有可能出现负权回路
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

// bellman-ford算法
void async function () {
    line = await readline();
    let [n, edge] = line.split(' ').map(Number),
        graph = [],
        minDist = new Array(n + 1).fill(Number.MAX_VALUE),
        start = 1;

    minDist[start] = 0
    while (line = await readline()) {
        // 存储所有边
        graph.push(line.split(' ').map(Number))
    }

    let flag = false;
    // 进行n次松弛,如果没有负权回路,最多进行n-1次松弛后,minDist数组将不会变化
    for (let i = 0; i <= n; i++) {
        for (let [left, right, val] of graph) {
            if (minDist[left] !== Number.MAX_VALUE && minDist[left] + val < minDist[right]) {
                if (i !== n) {
                    minDist[right] = minDist[left] + val
                } else {
                    flag = true
                    break;
                }
            }
        }
    }
    if (flag) {
        console.log("circle")
    } else {
        console.log(minDist[n] === Number.MAX_VALUE ? "unconnected" : minDist[n])
    }
}()


// bellman-fork优化版，SPFA
// 每个节点做多有n-1个入度，也就是说最多每个节点n-1次进入队列，如果大于n-1次，则存在负权回路
void async function () {
    line = await readline();
    let [n, edge] = line.split(' ').map(Number),
        graph = new Array(n + 1).fill(0).map(() => new Array()),
        minDist = new Array(n + 1).fill(Number.MAX_VALUE),
        inQueue = new Array(n + 1).fill(false),
        countArr = new Array(n + 1).fill(0),
        start = 1;

    minDist[1] = 0;
    while (line = await readline()) {
        let [left, right, val] = line.split(' ').map(Number);
        graph[left].push(new Edge(right, val));
    }

    let queue = [start],
        flag = false;
    countArr[start]++

    while (queue.length > 0) {
        let curNode = queue.shift();
        inQueue[curNode] = false
        for (let edgeItem of graph[curNode]) {
            // 开始松弛
            if (minDist[curNode] + edgeItem.val < minDist[edgeItem.to]) {
                minDist[edgeItem.to] = minDist[curNode] + edgeItem.val
                // 如果不再队列中，入队
                if (inQueue[edgeItem.to] === false) {
                    inQueue[edgeItem.to] = true
                    queue.push(edgeItem.to)
                    // 维护入队次数
                    countArr[edgeItem.to]++
                    if (countArr[edgeItem.to] === n) {
                        flag = true
                        queue = []
                        break
                    }
                }
            }
        }
    }

    if (flag) {
        console.log("circle")
    } else {
        console.log(minDist[n] === Number.MAX_VALUE ? "unconnected" : minDist[n])
    }
}()

class Edge {
    constructor(to, val) {
        this.to = to
        this.val = val
    }
}